# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Milan P. Stanić <mps@arvanta.net>
# Maintainer: Milan P. Stanić <mps@arvanta.net>
pkgname=zig
pkgver=0.6.0
pkgrel=2
pkgdesc="general-purpose programming language designed for robustness, optimality, and maintainability"
url="https://ziglang.org/"
arch="x86_64 aarch64"
license="MIT"
provides="zig-dev=$pkgver-r$pkgrel"
subpackages="$pkgname-doc"
makedepends="cmake clang-dev clang-libs llvm10-libs llvm-dev lld-dev libstdc++
	zlib-static libxml2-dev llvm10-static clang-static lld-static"
source="$pkgname-$pkgver.tar.gz::https://github.com/ziglang/zig/archive/$pkgver.tar.gz"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	mkdir -p build
	cd build
	cmake \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
		-DCMAKE_C_FLAGS="$CFLAGS" \
		${CMAKE_CROSSOPTS} \
		..
	make
}

check() {
	cd build
	./zig build test \
		-Dskip-release \
		-Dskip-release-small \
		-Dskip-release-fast \
		-Dskip-non-native \
		-Dskip-libc \
		-Dskip-self-hosted
}

package() {
	make -C build DESTDIR="$pkgdir" install

	# Documentation is generated as part of `./zig build test` in check().
	# If this is no longer the case at some point it can be
	# generated explicitly using `./zig build docs`.
	install -Dm644 zig-cache/langref.html \
		"$pkgdir"/usr/share/doc/$pkgname/langref.html
}

sha512sums="062f3437a080c1d823558c834dd143222e3f0537cc4256c4fa687ed94078a4312be60e402b0effa916ce8305a3482e1736a93c3ec4275fc5a526a0d78a3b1a47  zig-0.6.0.tar.gz"
